package com.yita.fruit.servlets;

import com.yita.fruit.dao.Impl.FruitDaoImpl;
import com.yita.fruit.pojo.Fruit;
import com.yita.myssm.myspringmvc.ViewBaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/add.do")
public class AddServlet extends ViewBaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String fname = req.getParameter("fname");
        String fprice = req.getParameter("price");
        String fcount = req.getParameter("fcount");
        String remark = req.getParameter("remark");
        Fruit fruit = new Fruit();
        fruit.setFname(fname);
        fruit.setPrice(Integer.valueOf(fprice));
        fruit.setFcount(Integer.parseInt(fcount));
        fruit.setRemark(remark);
        boolean b = new FruitDaoImpl().addFruit(fruit);
        System.out.println("添加结果：" + b);
        resp.sendRedirect("index");

    }
}
